<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="简书,Java,泛型," />










<meta name="description" content="关于Java泛型Bounded-Type-Parameters的理解">
<meta property="og:type" content="article">
<meta property="og:title" content="关于Java泛型Bounded-Type-Parameters的理解">
<meta property="og:url" content="http://wanazi.oschina.io/2018/11/12/关于Java泛型Bounded-Type-Parameters的理解/index.html">
<meta property="og:site_name" content="wanazi">
<meta property="og:description" content="关于Java泛型Bounded-Type-Parameters的理解">
<meta property="og:updated_time" content="2019-02-27T12:55:14.690Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="关于Java泛型Bounded-Type-Parameters的理解">
<meta name="twitter:description" content="关于Java泛型Bounded-Type-Parameters的理解">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://wanazi.oschina.io/2018/11/12/关于Java泛型Bounded-Type-Parameters的理解/"/>





  <title>关于Java泛型Bounded-Type-Parameters的理解 | wanazi</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">wanazi</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">偶尔记一些东西</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://wanazi.oschina.io/2018/11/12/关于Java泛型Bounded-Type-Parameters的理解/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="tqd">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="wanazi">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">关于Java泛型Bounded-Type-Parameters的理解</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-11-12T20:11:52+08:00">
                2018-11-12
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          
              <div class="post-description">
                  关于Java泛型Bounded-Type-Parameters的理解
              </div>
          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&#x6709;&#x754C;&#x7684;&#x7C7B;&#x578B;&#x53C2;&#x6570;&#xFF0C;&#x8FD9;&#x4E2A;&#x6709;&#x754C;&#x9650;&#x5B9A;&#x7684;&#x662F;&#x8FD9;&#x4E2A;&#x7C7B;&#x578B;&#x53C2;&#x6570;&#x662F;&#x6709;&#x754C;&#x7684;&#x3002;<br>&#x4E3E;&#x4F8B;&#x8BF4;&#x660E;&#xFF1A;<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">List&lt;? extends Number&gt; numbers=<span class="keyword">new</span> ArrayList&lt;&gt;();</div></pre></td></tr></table></figure></p>
<p>&#x8FD9;&#x91CC;&#x7684;&#xFF1F; extends Number&#x9650;&#x5B9A;&#x7684;&#x662F;&#x6CDB;&#x5316;&#x7C7B;List&#x7684;&#x7C7B;&#x578B;&#x53C2;&#x6570;&#x5FC5;&#x987B;&#x662F; Number&#x6216;&#x8005;Number&#x7684;&#x5B50;&#x7C7B;,List&lt;? extends Number&gt;&#x53EF;&#x4EE5;&#x662F;:</p>
<ul>
<li>List<integer></integer></li>
<li>List<float></float></li>
<li>List<double><br>&#x4E2D;&#x7684;&#x4E00;&#x79CD;&#xFF0C;&#x6240;&#x4EE5;&#x96C6;&#x5408;&#x4E2D;&#x5143;&#x7D20;&#x7684;&#x7C7B;&#x578B;&#x6211;&#x4EEC;&#x662F;&#x4E0D;&#x77E5;&#x9053;&#x7684;&#xFF0C;&#x5047;&#x5B9A;&#x6211;&#x4EEC;&#x8C03;&#x7528;List&lt;? extends Number&gt;&#x7C7B;&#x578B;&#x7684;add&#x65B9;&#x6CD5;<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">List&lt;? extends Number&gt; numbers=new ArrayList&lt;&gt;();</div><div class="line">Integer a=1;</div><div class="line">numbers.add(a);//&#x5982;&#x679C;&#x6B64;&#x65F6;numbers&#x7684;&#x5B9E;&#x9645;&#x7C7B;&#x578B;&#x662F;List&lt;Float&gt;,&#x90A3;&#x4E48;&#x5C31;&#x4F1A;&#x62A5;&#x9519;&#xFF0C;&#x56E0;&#x4E3A;Integer&#x7C7B;&#x578B;&#x4E0D;&#x80FD;&#x5F3A;&#x5236;&#x8F6C;&#x5316;&#x4E3A;Float&#x7C7B;&#x578B;</div></pre></td></tr></table></figure>
</double></li>
</ul>
<p>&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x4E0D;&#x80FD;&#x4F7F;&#x7528;Add&#x65B9;&#x6CD5;&#x6DFB;&#x52A0;&#x4EFB;&#x4F55;&#x7C7B;&#x578B;&#x7684;&#x5BF9;&#x8C61;&#xFF08;null&#x9664;&#x5916;&#xFF0C;null&#x53EF;&#x4EE5;&#x8D4B;&#x503C;&#x7ED9;&#x4EFB;&#x4F55;&#x5F15;&#x7528;&#x7C7B;&#x578B;&#xFF08;reference type&#xFF09;&#x7684;&#x53D8;&#x91CF;&#xFF09;&#x3002;<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">List&lt;? <span class="keyword">super</span> Number&gt; numbers=<span class="keyword">new</span> ArrayList&lt;&gt;();</div></pre></td></tr></table></figure></p>
<p>&#x8FD9;&#x91CC;&#x7684; &#xFF1F; super Number &#x9650;&#x5B9A;&#x7684;&#x662F;&#x6CDB;&#x5316;&#x7C7B;List&#x7684;&#x7C7B;&#x578B;&#x53C2;&#x6570;&#x5FC5;&#x987B;&#x662F;Number&#x6216;&#x8005;Number&#x7684;&#x7236;&#x7C7B;.List&lt;? super Number&gt;&#x53EF;&#x4EE5;&#x662F;</p>
<ul>
<li>List<number></number></li>
<li>List<object><br>&#x4E2D;&#x7684;&#x4E00;&#x79CD;&#xFF0C;&#x5047;&#x5B9A;&#x6211;&#x4EEC;&#x8C03;&#x7528;List&lt;? super Number&gt;&#x7C7B;&#x578B;&#x7684;add&#x65B9;&#x6CD5;<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">List&lt;? <span class="keyword">super</span> Number&gt; numbers=<span class="keyword">new</span> ArrayList&lt;&gt;();</div><div class="line">Integer a=<span class="number">1</span>;</div><div class="line">numbers.add(a);<span class="comment">//&#x4E0D;&#x7BA1;&#x6B64;&#x65F6;numbers&#x7684;&#x7C7B;&#x578B;&#x662F;&#x54EA;&#x79CD;&#xFF0C;Number&#x6216;&#x8005;Object,&#x90FD;&#x53EF;&#x4EE5;&#x5C06;Integer&#x7C7B;&#x578B;&#x76F4;&#x63A5;&#x8D4B;&#x503C;&#x7ED9;&#x5B83;&#x4EEC;&#xFF0C;&#x5B50;&#x7C7B;&#x5BF9;&#x8C61;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x8F6C;&#x5316;&#x4E3A;&#x7236;&#x7C7B;&#x5BF9;&#x8C61;</span></div><div class="line">Object c=<span class="keyword">new</span> Object();</div><div class="line">numbers1.add(c);<span class="comment">//&#x5047;&#x5B9A;&#x6B64;&#x65F6;numbers&#x7684;&#x7C7B;&#x578B;&#x4E3A;List&lt;Number&gt;,&#x90A3;&#x4E48;&#x5C31;&#x4F1A;&#x62A5;&#x9519;&#xFF0C;&#x56E0;&#x4E3A;Object&#x7C7B;&#x578B;&#x4E0D;&#x80FD;&#x5F3A;&#x5236;&#x8F6C;&#x5316;&#x4E3A;Number&#x7C7B;&#x578B;</span></div></pre></td></tr></table></figure>
</object></li>
</ul>
<p>&#x6240;&#x4EE5;&#x5C3D;&#x7BA1;&#x96C6;&#x5408;&#x4E2D;&#x7684;&#x5143;&#x7D20;&#x7C7B;&#x578B;&#x6211;&#x4EEC;&#x662F;&#x4E0D;&#x77E5;&#x9053;&#x7684;&#xFF0C;&#x4F46;&#x662F;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x6DFB;&#x52A0;Number&#x4EE5;&#x53CA;Number&#x5B50;&#x7C7B;&#x7684;&#x5BF9;&#x8C61;&#x3002;</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/简书/" rel="tag"># 简书</a>
          
            <a href="/tags/Java/" rel="tag"># Java</a>
          
            <a href="/tags/泛型/" rel="tag"># 泛型</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/10/31/windows-10-bash执行linux程序exit-code有问题/" rel="next" title="windows-10-bash执行linux程序exit-code有问题">
                <i class="fa fa-chevron-left"></i> windows-10-bash执行linux程序exit-code有问题
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/03/27/Windows下Rust开发环境配置/" rel="prev" title="Windows下Rust开发环境配置">
                Windows下Rust开发环境配置 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">tqd</p>
              <p class="site-description motion-element" itemprop="description">只是为了好玩</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">19</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">28</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">tqd</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
